package lib.quasar.qrcode;

import android.app.Activity;
import android.content.Intent;

/**
 * description: 扫一扫
 * created by kalu on 2018/4/4 9:24
 */
public class ZxingManager {

    public static final String INTENT_KEY_RESULT_SUCCESS = "intent_key_result_success";
    public static final String INTENT_KEY_RESULT_ERROR = "intent_key_result_error";
    public static final String INTENT_KEY_HINTTEXT = "intent_key_hinttext";
    public static final String INTENT_KEY_SCSNCOLOR = "intent_key_scsncolor";
    public static final String INTENT_KEY_PHOTO_FLAG = "intent_key_photo_flag";
    public static final String INTENT_KEY_BEEP_FLAG = "intent_key_beep_flag";
    public static final String INTENT_KEY_VIBRATE_FLAG = "intent_key_vibrate_flag";

    /**
     * 默认打开扫描页面
     *
     * @param context     上下文
     * @param requestCode If >= 0, this code will be returned in
     *                    onActivityResult() when the activity exits.
     */
    public static void startScan(Activity context, int requestCode, Class<?> clazz) {
        Intent intent = new Intent(context.getApplicationContext(), clazz);
        context.startActivityForResult(intent, requestCode);
    }

    public static void startScan(Activity context, int requestCode, ZxingConfig zxingConfig, Class<?> clazz) {
        Intent intent = new Intent(context.getApplicationContext(), clazz);
        //是否显示相册按钮
        intent.putExtra(INTENT_KEY_PHOTO_FLAG, zxingConfig.isShowPhotoAlbum());
        //识别声音
        intent.putExtra(INTENT_KEY_BEEP_FLAG, zxingConfig.isShowBeep());
        //识别震动
        intent.putExtra(INTENT_KEY_VIBRATE_FLAG, zxingConfig.isShowVibrate());
        //扫码框的颜色
        intent.putExtra(INTENT_KEY_SCSNCOLOR, zxingConfig.getScanColor());
        //扫码框上面的提示文案
        intent.putExtra(INTENT_KEY_HINTTEXT, zxingConfig.getScanHintText());
        context.startActivityForResult(intent, requestCode);
    }
}
